<template>
    <vol-box :lazy="true" v-model="model" title="选择设备" :width="1200" :padding="0">
        <div>
            <device ref="deviceRef"></device>
        </div>
        <template #footer>
            <div> <el-button type="primary" @click="onSelect">确认</el-button></div>
        </template>
    </vol-box>
</template>
<script setup>
import { ref, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance();
/******注意：如果出现提示没有权限的问题，见后台开发文档上的【重写后台权限】*****/
//直接引用生成的页面(也可以单独用table配置，单独配置下见下面【编辑弹出框明细表选择数据】)
import device from '@/views/mes/mes/Device.vue';
const deviceRef = ref();
const model = ref(false)

//是否单选(明细表格选择数据)
const single = ref(false);
const detailRow = ref({})
//回调
const emit = defineEmits('onSelectDevice')
const open = (row) => {
    //明细表表格选择数据传进来的当前行
    detailRow.value = row;
    //如果是明细表表格传进来的按钮，表格设置为单选
    single.value = !!row;
    model.value = true
    //打开时刷新界面数据
    nextTick(() => {
        deviceRef.value.$refs.grid.searchFormFields.IsEnabled = 1
        deviceRef.value.$refs.grid.searchFormFields.AuditStatus = 1
        deviceRef.value?.$refs.grid?.search()
    });
}
//选择数据
const onSelect = () => {

    let rows = deviceRef.value.$refs.grid.getSelectRows();
    if (!rows.length) {
        return proxy.$message.error('请选择数据');
    }
    if (detailRow.value) {
        detailRow.value.DeviceId = rows[0].DeviceId;
        detailRow.value.DeviceNumber = rows[0].Code;
        detailRow.value.DeviceName = rows[0].Name;
        detailRow.value.DeviceSpec = rows[0].Spec;
        detailRow.value.DeviceSize = rows[0].Size;
        detailRow.value.DeviceClassfiyId = rows[0].DeviceClassfiyId;
    } else {
        emit('onSelectDevice', rows)
    }

    model.value = false;
}
//暴露选择弹出框方法
defineExpose({ open })
</script>
<style lang="less" scoped>
.search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;

    button {
        margin-left: 10px;
    }
}
</style>